<?php
/**
 * Created by PhpStorm.
 * User: wenjoying@126.com
 * Date: 2018/5/31
 * Time: 10:16
 */

namespace App\Models;

use App\Http\Scopes\EnableScope;
use Exception;

class Task extends BaseModel
{
    const COL_ID = 'id';

    /**
     * @var string 表名
     */
    protected $table = 'task';

    /**
     * @var string 主键
     */
    protected $primaryKey = 'id';

    /**
     * 填充字段
     * @var array
     */
    protected $fillable = [
        'name',
        'start_at',
        'end_at',
        'process',
        'qr_asset_id',
        'question_num',
        'sign_in',
        'sign_out',
        'is_enable',
    ];

    /**
     * @desc 隐藏字段
     */
    protected $hidden = [];

    /**
     * @desc 动态增加字段
     */
    protected $appends = [];

    /**
     * @desc 查找字段
     */
    public $columns = [];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new EnableScope());
    }

    public function assignUser()
    {
        return $this->hasOne(Admin::class, 'admin_id', 'attach_id');
    }

    public function question()
    {
        return $this->hasMany(TaskQuestion::class, 'task_id')->orderByDesc('id');
    }


}